const https = require('https');

const url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=TkeRZlsfaq10RwkWFM0Qdgwy&client_secret=wQnXREQrbaCZ9yIVY8KU2xuLy71iiRMs';

console.log('正在测试百度云API连接...');
console.log('请求URL:', url);

https.get(url, (res) => {
    let data = '';
    
    res.on('data', (chunk) => {
        data += chunk;
    });
    
    res.on('end', () => {
        console.log('HTTP状态码:', res.statusCode);
        console.log('响应头:', res.headers);
        console.log('响应内容:', data);
        
        try {
            const jsonData = JSON.parse(data);
            if (jsonData.error) {
                console.log('API错误:', jsonData.error);
                console.log('错误描述:', jsonData.error_description);
            } else if (jsonData.access_token) {
                console.log('成功获取access_token:', jsonData.access_token);
                console.log('token有效期:', jsonData.expires_in, '秒');
            }
        } catch (e) {
            console.log('解析响应失败:', e.message);
        }
    });
}).on('error', (e) => {
    console.error('请求错误:', e.message);
});